<?php

/**
 * author : rookiejin <mrjnamei@gmail.com>
 * createTime : 2018/1/19 11:34
 * description: ArticleController.php - wingedcare-admin
 */

/**
 * Created by PhpStorm.
 * User: rookiejin <mrjnamei@gmail.com>
 * Date: 2018/1/19
 * Time: 11:34
 * description: ArticleController.php - wingedcare-admin
 */

namespace App\Http\Controllers;


use App\Article;
use Illuminate\Http\Request;

class ArticleController extends Controller
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse|int
     */
    public function getArticleList(Request $request)
    {
        try{
            $tenant_id = $request->header("tenantId");
            $category_id = $request->input("category_id","");
            $size = $request->input("size","10");
            $list = Article::where(['tenant_id' => $tenant_id,"category_id"=>$category_id , 'type' => 2 ])->orderBy("id","desc")->paginate($size);
            return response()->json(array_merge($list->toArray() ,['status' => 'SUCCESS']));
        }
        catch (\Exception $exception){
            return response()->json(array_merge($list->toArray() ,['status' => 'FAIL', 'message' => $exception->getMessage()]));
        }

    }
}
